package com.tancire.web.controller.platform.member;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.common.enums.BusinessType;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.member.domain.MemberPurse;
import com.tancire.member.service.IMemberPurseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员钱包Controller
 *
 * @author tancire
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/member/memberPurse")
public class MemberPurseController extends BaseController {
    @Resource
    private IMemberPurseService memberPurseService;

    /**
     * 查询会员钱包列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberPurse:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberPurse memberPurse) {
        startPage();
        List<MemberPurse> list = memberPurseService.selectMemberPurseList(memberPurse);
        return getDataTable(list);
    }

    /**
     * 导出会员钱包列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberPurse:export')")
    @Log(title = "会员钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberPurse memberPurse) {
        List<MemberPurse> list = memberPurseService.selectMemberPurseList(memberPurse);
        ExcelUtil<MemberPurse> util = new ExcelUtil<MemberPurse>(MemberPurse.class);
        util.exportExcel(response, list, "会员钱包数据");
    }

    /**
     * 获取会员钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:memberPurse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(memberPurseService.selectMemberPurseById(id));
    }

    /**
     * 新增会员钱包
     */
    @PreAuthorize("@ss.hasPermi('member:memberPurse:add')")
    @Log(title = "会员钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberPurse memberPurse) {
        return toAjax(memberPurseService.insertMemberPurse(memberPurse));
    }

    /**
     * 修改会员钱包
     */
    @PreAuthorize("@ss.hasPermi('member:memberPurse:edit')")
    @Log(title = "会员钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberPurse memberPurse) {
        return toAjax(memberPurseService.updateMemberPurse(memberPurse));
    }

    /**
     * 删除会员钱包
     */
    @PreAuthorize("@ss.hasPermi('member:memberPurse:remove')")
    @Log(title = "会员钱包", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(memberPurseService.deleteMemberPurseByIds(ids));
    }
}
